import java.util.*;

class Student implements Comparable<Student>{
    private int age;
    private String name;
    private double score;
    public Student(int age) {
        this.age = age;
    }
    public Student(String name) {
        this.name = name;
    }
    public Student(double score) {
        this.score = score;
    }
    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public int compareTo(Student o) {   //重写compareTo方法，才能用
        return (int)(this.score-o.score);
    }
}


public class Test {
    public static ArrayList<Character> func(String str1,String str2) {
        ArrayList<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {   //只写ch不行，要+“”变成string类型
                arrayList.add(ch);
            }
        }
        return arrayList;
    }

    public static void main(String[] args) {
        ArrayList<Character> ans = new ArrayList<>();
        for (int i = 0; i < ans.size(); i++) {
            System.out.println(ans.get(i));
        }
    }

    public static void main4(String[] args) {
        ArrayList<Student> arrayList= new ArrayList<>();
        arrayList.add(new Student(10,"小林",90));
        arrayList.add(new Student(15,"小王",90));
        for (Student x: arrayList) {
            System.out.println(x);
        }

        Collections.sort(arrayList);    //重写compareTo方法才能用sort
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        arrayList1.add(3);
        arrayList1.add(4);
        arrayList1.add(5);

        //三种遍历方式：
        int size = arrayList1.size();
        for (int i = 0; i < size; i++) {
            System.out.print(arrayList1.get(i) + " ");
        }
        System.out.println();

        for (Integer x : arrayList1) {    //用foreach
            System.out.println(x + " ");
        }
        System.out.println();
        ListIterator<Integer> it = arrayList1.listIterator();     //迭代器
        while(it.hasNext()) {
            System.out.println(it.next() + " ");   //it一直在数据上方 it.next()不仅往下走而且返回当前数据
        }
        System.out.println();

    }

    public static void main2(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(0,7);

        arrayList1.remove(0);    //传数字，认为是下标
        arrayList1.remove(new Integer(7));  //传引用类型，才会查找该数据

        List<Integer> list = arrayList1.subList(1,3);   //用list来接收截取的2-3部分
        list.set(0,99);   //更新list中数据，原数据也会变

    }

    public static void main1(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);      //调用不带参数的构造方法时，只有第一次add时才会分配10的内存
        arrayList1.add(11);     //到第11个数时，1.5倍扩容
        System.out.println(arrayList1);   //Collection里重写的toString方法

        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList1);  //把1中的元素放到2里
        //ArrayList<String> arrayList3 = new ArrayList<>();
        //ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList3);  报错，传进去的类型String不是Integer或其子类
        LinkedList<Integer> arrayList3 = new LinkedList<>();
        ArrayList<Integer> arrayList4 = new ArrayList<>(arrayList3);  //可以，LinkedList实现了Collections


    }
}
